<template>
  <div id="DataMaintenance-groupInformationSet-gardenRelatedSet">
    <div class="right-btn">
      <template v-if="isShowEdit">
        <el-button size="mini" @click="isShowEdit = false">{{
          $t(
            "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsh080"
          )
        }}</el-button>
        <el-button type="primary" size="mini" @click="onSubmit">{{
          $t(
            "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrslec0"
          )
        }}</el-button>
      </template>
      <el-button v-else type="primary" size="mini" @click="isShowEdit = true">{{
        $t(
          "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsm3w0"
        )
      }}</el-button>
    </div>
    <div class="body groupInformationSet-gardenRelatedSet pl12 pr12 pt20 pb20">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="220px"
      >
        <template v-if="isShowEdit">
          <el-form-item
            :label="
              $t(
                'groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmjo0'
              )
            "
            prop="company_isclientshare"
          >
            <el-radio-group v-model="ruleForm[0].company_isclientshare">
              <el-radio label="1">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0"
                )
              }}</el-radio>
              <el-radio label="0">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0"
                )
              }}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="是否允许园所添加主体:">
            <el-radio-group v-model="ruleForm[1].company_companiesfree">
              <el-radio label="1">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0"
                )
              }}</el-radio>
              <el-radio label="0">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0"
                )
              }}</el-radio>
            </el-radio-group>
            <el-popover
              placement="right"
              trigger="hover"
              popper-class="setting-popover"
              content="选择是园所可自己添加企业主体信息，选择否则不允许添加"
            >
              <i class="ml10 el-icon-question" slot="reference"></i>
            </el-popover>
          </el-form-item>
          <el-form-item label="不同主体交易转移是否需要审核:">
            <el-radio-group v-model="ruleForm[2].company_trans_isaudit">
              <el-radio label="1">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0"
                )
              }}</el-radio>
              <el-radio label="0">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0"
                )
              }}</el-radio>
            </el-radio-group>
            <el-popover
              placement="right"
              trigger="hover"
              popper-class="setting-popover"
              content="选择是园所需审核不同主体之间的资金交易转移，选择否则不需要审核"
            >
              <i class="ml10 el-icon-question" slot="reference"></i>
            </el-popover>
          </el-form-item>
          <el-form-item label="是否允许退部分项目金额:">
            <el-radio-group v-model="ruleForm[3].company_partrefund_permit">
              <el-radio label="1">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0"
                )
              }}</el-radio>
              <el-radio label="0">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0"
                )
              }}</el-radio>
            </el-radio-group>
            <el-popover
              placement="right"
              trigger="hover"
              popper-class="setting-popover"
              content="选择是幼儿退预收余额时可选择退部分项目金额，否则不允许"
            >
              <i class="ml10 el-icon-question" slot="reference"></i>
            </el-popover>
          </el-form-item>
        </template>
        <!-- <el-form-item :label="ruleTitle[index]" v-for="(item,index) in ruleForm" :key="index">
            <el-radio-group v-model="item.state">
              <el-radio label="1">{{$t('groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0')}}</el-radio>
              <el-radio label="0">{{$t('groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0')}}</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-tooltip class="item" effect="dark" content="Right Center 提示文字" placement="bottom-start">
            <i class="el-icon-question" />
          </el-tooltip>
        </template> -->

        <template v-else>
          <!-- //意向名单是否愿意共享 -->
          <el-form-item
            :label="
              $t(
                'groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmjo0'
              )
            "
          >
            <el-radio-group
              disabled
              v-model="ruleForm[0].company_isclientshare"
            >
              <el-radio label="1">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0"
                )
              }}</el-radio>
              <el-radio label="0">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0"
                )
              }}</el-radio>
            </el-radio-group>
          </el-form-item>

          <!-- //是否允许园所添加主体 -->
          <el-form-item label="是否允许园所添加主体:">
            <el-radio-group
              disabled
              v-model="ruleForm[1].company_companiesfree"
            >
              <el-radio label="1">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0"
                )
              }}</el-radio>
              <el-radio label="0">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0"
                )
              }}</el-radio>
            </el-radio-group>
          </el-form-item>

          <!-- //不同主体交易转移是否需要审核 -->
          <el-form-item label="不同主体交易转移是否需要审核:">
            <el-radio-group
              disabled
              v-model="ruleForm[2].company_trans_isaudit"
            >
              <el-radio label="1">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0"
                )
              }}</el-radio>
              <el-radio label="0">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0"
                )
              }}</el-radio>
            </el-radio-group>
          </el-form-item>

          <!-- //是否允许退部分项目金额 -->
          <el-form-item label="是否允许退部分项目金额:">
            <el-radio-group
              disabled
              v-model="ruleForm[3].company_partrefund_permit"
            >
              <el-radio label="1">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsmxc0"
                )
              }}</el-radio>
              <el-radio label="0">{{
                $t(
                  "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnbg0"
                )
              }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </template>
      </el-form>
    </div>
  </div>
</template>

<script>
import setHttp from "../../Set";

export default {
  name: "setting",
  components: {},
  data() {
    return {
      isShowEdit: false, //是否显示编辑
      //表单选择名字
      // 表单
      // ruleForm: {
      //   company_isclientshare: "0", //意向名单是否共享 0否 1是
      //   isprincipal:"0", //是否允许园所自行添加 测试
      //   isexamine:"0", //不同主体交易转移是否需要审核
      //   isreturn:"0" ,    //是否允许退部分项目金额
      // },
      ruleForm: [
        { company_isclientshare: "1" },
        { company_companiesfree: "1" },
        { company_trans_isaudit: "1" },
        { company_partrefund_permit: "1" },
      ],
      // 表单验证
      rules: {
        company_isclientshare: [
          {
            required: true,
            message: this.$t(
              "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsnvg0"
            ),
            trigger: "change",
          },
        ],
      },
    };
  },
  created() {
    this.getCompanySettingApi();
  },
  methods: {
    // 集团资料->获取集团设置->lujing
    getCompanySettingApi() {
      setHttp.getCompanySettingApi({}).then((res) => {
        console.log(res.data.result.data);
        if (res.data.error == 0) {
          this.ruleForm[0].company_isclientshare =
            res.data.result.data.company_isclientshare;
          this.ruleForm[1].company_companiesfree =
            res.data.result.data.company_companiesfree;
          this.ruleForm[2].company_trans_isaudit =
            res.data.result.data.company_trans_isaudit;
          this.ruleForm[3].company_partrefund_permit =
            res.data.result.data.company_partrefund_permit;
        } else {
          this.ruleForm[0].company_isclientshare = "0";
          this.ruleForm[1].company_companiesfree = "0";
          this.ruleForm[2].company_trans_isaudit = "0";
          this.ruleForm[3].company_partrefund_permit = "0";
        }
      });
    },
    //集团资料->设置集团设置->lujing
    setCompanySettingAction() {
      setHttp
        .setCompanySettingAction({
          setting_field: JSON.stringify(this.ruleForm),
        })
        .then((res) => {
          if (res.data.error == 0) {
            this.$message({ message: res.data.errortip, type: "success" });
            this.isShowEdit = false;
            this.getCompanySettingApi();
          } else {
            this.$message.error(res.data.errortip);
          }
        });
    },
    //编辑- 提交
    onSubmit() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          this.setCompanySettingAction();
        } else {
          this.$message.warning(
            this.$t(
              "groupInformationSet.groupInfoSettings.gardenRelatedSet.5633gyrsokg0"
            )
          );
          return false;
        }
      });
    },
    // 重置表单
    resetForm(form) {
      // 数据清空
      this.ruleForm = [
        { company_isclientshare: "0" },
        { company_companiesfree: "0" },
        { company_trans_isaudit: "0" },
        { company_partrefund_permit: "0" },
      ];
      if (this.$refs[form]) {
        this.$refs[form].resetFields();
      }
    },
    //侧边弹窗-关闭
    handleClose(done) {
      done();
    },
  },
  mounted() {},
};
</script>
<style>
.setting-popover {
  color: #ffa210;
  background-color: #fff8e7;
  padding: 10px;
}
</style>
<style lang="less" scoped>
#DataMaintenance-groupInformationSet-gardenRelatedSet {
}
</style>
